package com.dfbz.homework3;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class test {
    //1.通过Class对象的方法创建。
    @Test
    public void test() throws IllegalAccessException, InstantiationException {
        //获得学生的字节码文件
        Class<Student> studentClass = Student.class;
        Student student = studentClass.newInstance();
        student.setAge(20);
        student.setName("hehe");
        student.show();
    }
    //2.通过Constructor对象的方法创建。
    @Test
    public void test1() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<Student> studentClass = Student.class;
        Constructor<Student> constructor = studentClass.getConstructor(String.class, int.class);
        Student student = constructor.newInstance("张三", 20);
        System.out.println(student);

    }


}
